﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using DCMS_Framework;

namespace BusinessObjects {
  /// <summary>
  /// Child Schedule class
  /// </summary>
  public class Schedule : ObjectBase {

    string week1MoFrom, week1MoTo, week1TuFrom, week1TuTo, week1WeFrom;
    string week1WeTo, week1ThFrom, week1ThTo, week1FrFrom, week1FrTo;
    string week2MoFrom, week2MoTo, week2TuFrom, week2TuTo, week2WeFrom;
    string week2WeTo, week2ThFrom, week2ThTo, week2FrFrom, week2FrTo;
    string week3MoFrom, week3MoTo, week3TuFrom, week3TuTo, week3WeFrom;
    string week3WeTo, week3ThFrom, week3ThTo, week3FrFrom, week3FrTo;
    string week4MoFrom, week4MoTo, week4TuFrom, week4TuTo, week4WeFrom;
    string week4WeTo, week4ThFrom, week4ThTo, week4FrFrom, week4FrTo;
    private ScheduleType type;
    private int id;

    #region - Properties -

    /// <summary>
    /// Gets or sets the id.
    /// </summary>
    /// <value>
    /// The id.
    /// </value>
    public int Id {
      get { return id; }
      set {
        SetField( ref id, value, "Id" );
      }
    }

    /// <summary>
    /// Gets a value indicating whether this instance is new.
    /// </summary>
    /// <value>
    ///   <c>true</c> if this instance is new; otherwise, <c>false</c>.
    /// </value>
    public bool IsNew {
      get {
        if ( Id == 0 ) {
          return true;
        } else {
          return false;
        }
      }
    }

    /// <summary>
    /// Gets or sets the schedule type.
    /// </summary>
    /// <value>
    /// The type.
    /// </value>
    public ScheduleType Type {
      get { return type; }
      set {
        SetField( ref type, value, "Type" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 mo from.
    /// </summary>
    /// <value>
    /// The week1 mo from.
    /// </value>
    public string Week1MoFrom {
      get { return week1MoFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1MoFrom, value, "Week1MoFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 mo to.
    /// </summary>
    /// <value>
    /// The week1 mo to.
    /// </value>
    public string Week1MoTo {
      get { return week1MoTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1MoTo, value, "Week1MoTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 tu from.
    /// </summary>
    /// <value>
    /// The week1 tu from.
    /// </value>
    public string Week1TuFrom {
      get { return week1TuFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1TuFrom, value, "Week1TuFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 tu to.
    /// </summary>
    /// <value>
    /// The week1 tu to.
    /// </value>
    public string Week1TuTo {
      get { return week1TuTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1TuTo, value, "Week1TuTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 we from.
    /// </summary>
    /// <value>
    /// The week1 we from.
    /// </value>
    public string Week1WeFrom {
      get { return week1WeFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1WeFrom, value, "Week1WeFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 we to.
    /// </summary>
    /// <value>
    /// The week1 we to.
    /// </value>
    public string Week1WeTo {
      get { return week1WeTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1WeTo, value, "Week1WeTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 th from.
    /// </summary>
    /// <value>
    /// The week1 th from.
    /// </value>
    public string Week1ThFrom {
      get { return week1ThFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1ThFrom, value, "Week1ThFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 th to.
    /// </summary>
    /// <value>
    /// The week1 th to.
    /// </value>
    public string Week1ThTo {
      get { return week1ThTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1ThTo, value, "Week1ThTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 fr from.
    /// </summary>
    /// <value>
    /// The week1 fr from.
    /// </value>
    public string Week1FrFrom {
      get { return week1FrFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1FrFrom, value, "Week1FrFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week1 fr to.
    /// </summary>
    /// <value>
    /// The week1 fr to.
    /// </value>
    public string Week1FrTo {
      get { return week1FrTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week1FrTo, value, "Week1FrTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 mo from.
    /// </summary>
    /// <value>
    /// The week2 mo from.
    /// </value>
    public string Week2MoFrom {
      get { return week2MoFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2MoFrom, value, "Week2MoFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 mo to.
    /// </summary>
    /// <value>
    /// The week2 mo to.
    /// </value>
    public string Week2MoTo {
      get { return week2MoTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2MoTo, value, "Week2MoTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 tu from.
    /// </summary>
    /// <value>
    /// The week2 tu from.
    /// </value>
    public string Week2TuFrom {
      get { return week2TuFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2TuFrom, value, "Week2TuFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 tu to.
    /// </summary>
    /// <value>
    /// The week2 tu to.
    /// </value>
    public string Week2TuTo {
      get { return week2TuTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2TuTo, value, "Week2TuTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 we from.
    /// </summary>
    /// <value>
    /// The week2 we from.
    /// </value>
    public string Week2WeFrom {
      get { return week2WeFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2WeFrom, value, "Week2WeFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 we to.
    /// </summary>
    /// <value>
    /// The week2 we to.
    /// </value>
    public string Week2WeTo {
      get { return week2WeTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2WeTo, value, "Week2WeTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 th from.
    /// </summary>
    /// <value>
    /// The week2 th from.
    /// </value>
    public string Week2ThFrom {
      get { return week2ThFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2ThFrom, value, "Week2ThFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 th to.
    /// </summary>
    /// <value>
    /// The week2 th to.
    /// </value>
    public string Week2ThTo {
      get { return week2ThTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2ThTo, value, "Week2ThTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 fr from.
    /// </summary>
    /// <value>
    /// The week2 fr from.
    /// </value>
    public string Week2FrFrom {
      get { return week2FrFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2FrFrom, value, "Week2FrFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week2 fr to.
    /// </summary>
    /// <value>
    /// The week2 fr to.
    /// </value>
    public string Week2FrTo {
      get { return week2FrTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week2FrTo, value, "Week2FrTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 mo from.
    /// </summary>
    /// <value>
    /// The week3 mo from.
    /// </value>
    public string Week3MoFrom {
      get { return week3MoFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3MoFrom, value, "Week3MoFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 mo to.
    /// </summary>
    /// <value>
    /// The week3 mo to.
    /// </value>
    public string Week3MoTo {
      get { return week3MoTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3MoTo, value, "Week3MoTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 tu from.
    /// </summary>
    /// <value>
    /// The week3 tu from.
    /// </value>
    public string Week3TuFrom {
      get { return week3TuFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3TuFrom, value, "Week3TuFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 tu to.
    /// </summary>
    /// <value>
    /// The week3 tu to.
    /// </value>
    public string Week3TuTo {
      get { return week3TuTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3TuTo, value, "Week3TuTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 we from.
    /// </summary>
    /// <value>
    /// The week3 we from.
    /// </value>
    public string Week3WeFrom {
      get { return week3WeFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3WeFrom, value, "Week3WeFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 we to.
    /// </summary>
    /// <value>
    /// The week3 we to.
    /// </value>
    public string Week3WeTo {
      get { return week3WeTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3WeTo, value, "Week3WeTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 th from.
    /// </summary>
    /// <value>
    /// The week3 th from.
    /// </value>
    public string Week3ThFrom {
      get { return week3ThFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3ThFrom, value, "Week3ThFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 th to.
    /// </summary>
    /// <value>
    /// The week3 th to.
    /// </value>
    public string Week3ThTo {
      get { return week3ThTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3ThTo, value, "Week3ThTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 fr from.
    /// </summary>
    /// <value>
    /// The week3 fr from.
    /// </value>
    public string Week3FrFrom {
      get { return week3FrFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3FrFrom, value, "Week3FrFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week3 fr to.
    /// </summary>
    /// <value>
    /// The week3 fr to.
    /// </value>
    public string Week3FrTo {
      get { return week3FrTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week3FrTo, value, "Week3FrTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 mo from.
    /// </summary>
    /// <value>
    /// The week4 mo from.
    /// </value>
    public string Week4MoFrom {
      get { return week4MoFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4MoFrom, value, "Week4MoFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 mo to.
    /// </summary>
    /// <value>
    /// The week4 mo to.
    /// </value>
    public string Week4MoTo {
      get { return week4MoTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4MoTo, value, "Week4MoTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 tu from.
    /// </summary>
    /// <value>
    /// The week4 tu from.
    /// </value>
    public string Week4TuFrom {
      get { return week4TuFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4TuFrom, value, "Week4TuFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 tu to.
    /// </summary>
    /// <value>
    /// The week4 tu to.
    /// </value>
    public string Week4TuTo {
      get { return week4TuTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4TuTo, value, "Week4TuTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 we from.
    /// </summary>
    /// <value>
    /// The week4 we from.
    /// </value>
    public string Week4WeFrom {
      get { return week4WeFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4WeFrom, value, "Week4WeFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 we to.
    /// </summary>
    /// <value>
    /// The week4 we to.
    /// </value>
    public string Week4WeTo {
      get { return week4WeTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4WeTo, value, "Week4WeTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 th from.
    /// </summary>
    /// <value>
    /// The week4 th from.
    /// </value>
    public string Week4ThFrom {
      get { return week4ThFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4ThFrom, value, "Week4ThFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 th to.
    /// </summary>
    /// <value>
    /// The week4 th to.
    /// </value>
    public string Week4ThTo {
      get { return week4ThTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4ThTo, value, "Week4ThTo" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 fr from.
    /// </summary>
    /// <value>
    /// The week4 fr from.
    /// </value>
    public string Week4FrFrom {
      get { return week4FrFrom; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4FrFrom, value, "Week4FrFrom" );
      }
    }

    /// <summary>
    /// Gets or sets the week4 fr to.
    /// </summary>
    /// <value>
    /// The week4 fr to.
    /// </value>
    public string Week4FrTo {
      get { return week4FrTo; }
      set {
        if ( !string.IsNullOrEmpty( value ) && value.Trim( ) == ":" ) {
          value = null;
        }
        SetField( ref week4FrTo, value, "Week4FrTo" );
      }
    }

    /// <summary>
    /// Gets the type description.
    /// </summary>
    public string TypeDescription {
      get {
        return EnumUtils.GetDescription( this.type );
      }
    }

    /// <summary>
    /// Gets a value indicating whether [week1 is set].
    /// </summary>
    /// <value>
    ///   <c>true</c> if [week1 is set]; otherwise, <c>false</c>.
    /// </value>
    public bool Week1IsSet {
      get {
        if ( string.IsNullOrEmpty( week1MoFrom ) && string.IsNullOrEmpty( week1MoTo )
          && string.IsNullOrEmpty( week1TuFrom ) && string.IsNullOrEmpty( week1TuTo )
          && string.IsNullOrEmpty( week1WeFrom ) && string.IsNullOrEmpty( week1WeTo )
          && string.IsNullOrEmpty( week1ThFrom ) && string.IsNullOrEmpty( week1ThTo )
          && string.IsNullOrEmpty( week1FrFrom ) && string.IsNullOrEmpty( week1FrTo ) ) {
          return false;
        } else {
          return true;
        }
      }
    }

    /// <summary>
    /// Gets a value indicating whether [week2 is set].
    /// </summary>
    /// <value>
    ///   <c>true</c> if [week2 is set]; otherwise, <c>false</c>.
    /// </value>
    public bool Week2IsSet {
      get {
        if ( string.IsNullOrEmpty( week2MoFrom ) && string.IsNullOrEmpty( week2MoTo )
         && string.IsNullOrEmpty( week2TuFrom ) && string.IsNullOrEmpty( week2TuTo )
         && string.IsNullOrEmpty( week2WeFrom ) && string.IsNullOrEmpty( week2WeTo )
         && string.IsNullOrEmpty( week2ThFrom ) && string.IsNullOrEmpty( week2ThTo )
         && string.IsNullOrEmpty( week2FrFrom ) && string.IsNullOrEmpty( week2FrTo ) ) {
          return false;
        } else {
          return true;
        }
      }
    }

    /// <summary>
    /// Gets a value indicating whether [week3 is set].
    /// </summary>
    /// <value>
    ///   <c>true</c> if [week3 is set]; otherwise, <c>false</c>.
    /// </value>
    public bool Week3IsSet {
      get {
        if ( string.IsNullOrEmpty( week3MoFrom ) && string.IsNullOrEmpty( week3MoTo )
         && string.IsNullOrEmpty( week3TuFrom ) && string.IsNullOrEmpty( week3TuTo )
         && string.IsNullOrEmpty( week3WeFrom ) && string.IsNullOrEmpty( week3WeTo )
         && string.IsNullOrEmpty( week3ThFrom ) && string.IsNullOrEmpty( week3ThTo )
         && string.IsNullOrEmpty( week3FrFrom ) && string.IsNullOrEmpty( week3FrTo ) ) {
          return false;
        } else {
          return true;
        }
      }
    }

    /// <summary>
    /// Gets a value indicating whether [week4 is set].
    /// </summary>
    /// <value>
    ///   <c>true</c> if [week4 is set]; otherwise, <c>false</c>.
    /// </value>
    public bool Week4IsSet {
      get {
        if ( string.IsNullOrEmpty( week4MoFrom ) && string.IsNullOrEmpty( week4MoTo )
         && string.IsNullOrEmpty( week4TuFrom ) && string.IsNullOrEmpty( week4TuTo )
         && string.IsNullOrEmpty( week4WeFrom ) && string.IsNullOrEmpty( week4WeTo )
         && string.IsNullOrEmpty( week4ThFrom ) && string.IsNullOrEmpty( week4ThTo )
         && string.IsNullOrEmpty( week4FrFrom ) && string.IsNullOrEmpty( week4FrTo ) ) {
          return false;
        } else {
          return true;
        }
      }
    }

    #endregion

    #region - Methods -

    /// <summary>
    /// Clears the schedule.
    /// </summary>
    public void Clear( ) {
      ClearWeek1( );
      ClearWeek2( );
      ClearWeek3( );
      ClearWeek4( );
    }

    /// <summary>
    /// Clears week 4 of the schedule.
    /// </summary>
    public void ClearWeek4( ) {
      week4MoFrom = string.Empty;
      week4MoTo = string.Empty;
      week4TuFrom = string.Empty;
      week4TuTo = string.Empty;
      week4WeFrom = string.Empty;
      week4WeTo = string.Empty;
      week4ThFrom = string.Empty;
      week4ThTo = string.Empty;
      week4FrFrom = string.Empty;
      week4FrTo = string.Empty;
    }

    /// <summary>
    /// Clears week 3 of the schedule.
    /// </summary>
    public void ClearWeek3( ) {
      week3MoFrom = string.Empty;
      week3MoTo = string.Empty;
      week3TuFrom = string.Empty;
      week3TuTo = string.Empty;
      week3WeFrom = string.Empty;
      week3WeTo = string.Empty;
      week3ThFrom = string.Empty;
      week3ThTo = string.Empty;
      week3FrFrom = string.Empty;
      week3FrTo = string.Empty;
    }

    /// <summary>
    /// Clears week 2 of the schedule.
    /// </summary>
    public void ClearWeek2( ) {
      week2MoFrom = string.Empty;
      week2MoTo = string.Empty;
      week2TuFrom = string.Empty;
      week2TuTo = string.Empty;
      week2WeFrom = string.Empty;
      week2WeTo = string.Empty;
      week2ThFrom = string.Empty;
      week2ThTo = string.Empty;
      week2FrFrom = string.Empty;
      week2FrTo = string.Empty;
    }

    /// <summary>
    /// Clears week 1 of the schedule.
    /// </summary>
    public void ClearWeek1( ) {
      week1MoFrom = string.Empty;
      week1MoTo = string.Empty;
      week1TuFrom = string.Empty;
      week1TuTo = string.Empty;
      week1WeFrom = string.Empty;
      week1WeTo = string.Empty;
      week1ThFrom = string.Empty;
      week1ThTo = string.Empty;
      week1FrFrom = string.Empty;
      week1FrTo = string.Empty;
    }

    #endregion

    /// <summary>
    /// ScheduleType
    /// </summary>
    public enum ScheduleType : byte {

      [DescriptionAttribute( "weekelijks" )]
      Weekly,
      [DescriptionAttribute( "2-weekelijks" )]
      Twoweekly,
      [DescriptionAttribute( "maandelijks" )]
      Monthly,
      [DescriptionAttribute( "variabel" )]
      Variable
    }

  }
}
